$(function(){
	window.indexTabset = $('.article-box').ftabset({
		'defaultTabData':[{
			'id':'home',
			'name':'首页',
			'url':ctx + '/datum/platform',
			'active':true
		}],
		'style':'classic'
	});
	$("#main-nav").find("a[data-menu]").on('click',function(e){
		e.stopPropagation();
		e.preventDefault();
		var $this = $(this);
		var id = $this.attr("id");
		var url = $this.data("url");
		var name = $this.data("text");
		$("#main-nav").find("a[data-menu].active").removeClass("active");
		$this.addClass("active");
		// alert('id = ' + id + ', url = ' + url + ', name = ' + name + ', indexTabset == null -> ' + (indexTabset == null) );
		indexTabset.activeMenu(id, name, url);
	});
	
	window.setInterval(function() {
		var timestamp = new Date().getTime();
		$.ajax({
			url : ctx + "/heartBeat/" + timestamp
		});
	}, 300000); // 5分钟一次 
});
var IndexPage = {
	// 切换角色
	switchRole:function(ele) {
		// alert('hh');
		MsgBox.open("switchRole","切换角色",ctx + "/index/switchRole","320px");
	},
	// 修改密码
	updatePwd:function(ele) {
		MsgBox.open("updatePwd","修改密码",ctx + "/index/updatePwd","400px");
	},
	toggleLocker:function(userStatus) {
		var $ele = $(".t-menu-locker>a");
		var status = $ele.attr('data-status');
		if (userStatus != null) {
			status = userStatus;
		}
		if (status == 'open') {
			$('body').removeClass("big-page");
			$ele.attr("data-status", "close");
		} else if (status == 'close') {
			$('body').addClass("big-page");
			$ele.attr("data-status", "open");
		}
	},
	// 用户设置
	'userSetting': function(ele) {
		MsgBox.open("userSetting", "设置", ctx + "/setting/index","600px");
	},
	// 查询用户设置成功回调
	'findAutoMenuSettingSucc': function(data, status, xhr) {
		if (data.info == null) {
			return;
		}
		var menuIds = data.info.settingValues;
		if (!ArrayUtil.hasData(menuIds)) {
			return ;
		}
		$.each(menuIds, function(index, item) {
			$("#main-nav").find("a[data-menu]").filter("#M_" + item)[0].click();
		});
	}
};